<?php

class DefaultController extends BackOfficeController
{
	public function actionIndex()
	{
		$this->render('index');
	}
    
    /**
    * Login in BackOffice
    */
    public function actionLogin(){
        Yii::import('User.models.User');
        $user = new User();
        $invalidStatusCase = false;
        if (Yii::app()->request->IsPostRequest) {
            $result = FSM::run('User.user.login', $_POST);
            $user = $result->model;
            if ($this->post('ajax','') == 'user-login-form'){
                echo $result->getActiveErrorMessages($user);
                Yii::app()->end();
            }
            if (! $result->hasErrors()){
                if (($url = Yii::app()->user->returnUrl) != '')
                    Yii::app()->controller->redirect($url);
                else
                    $this->redirect(Yii::app()->request->getBaseUrl(true));
            }
        }
        if (Yii::app()->user->isGuest === false) {
            $this->redirect(Yii::app()->request->getBaseUrl(true));
        }
        $this->layout = '//layouts/login';
        $this->render('login', array('model' => $user));
    }
}